#ifndef __Model3DataBasePublic_H__
#define __Model3DataBasePublic_H__

#include "OccDatabase/Export"

#include "OccDatabase/DatasPublic.h"


enum RecordOperatorType
{
	ShapeDeleteOperator = 3000, ShapeAddOperator
};

struct DataBaseRecord
{
	DataBaseRecord()
	{
		isFirstAdd = false;
	}
	CDateChaiDan* shape;
	RecordOperatorType operator_type;

	bool isFirstAdd;
};

class OccDatabase_EXPORT DataBaseManager
{
private:
	static std::vector<DataBaseRecord> k_records;
	static std::stack<std::vector<DataBaseRecord>> k_undo_stack;
	static std::stack<std::vector<DataBaseRecord>> k_redo_stack;

public:
	
	static void AddShape(CDateChaiDan* shape,  std::string operator_name = "");
	static void DeleteShape(CDateChaiDan* shape);

	static void BegineCommit();
	static void EndCommit();

	static void UndoStack();
	static void RedoStack();


private:
	static void ExecuteRecords(std::vector<DataBaseRecord> &records);

	static void ClearRecordStack(std::stack<std::vector<DataBaseRecord>> &src_stack);
	static void ChangeOperator(std::vector<DataBaseRecord>& records);
};

class OccDatabase_EXPORT DataBase
{
	friend class DataBaseManager;

private:
	static DataBase* _Instance;
	
public:
	static DataBase* Instance();
	~DataBase();

public:
	DataBase();

public:
	bool AddShape( CDateChaiDan* shape);
	bool DeleteShape( CDateChaiDan* shape);

	void openFile(std::string path);
	void saveFile(std::string path);

	std::string addConstructor(std::string className, pConstructor p);

public:

	int mNum;

	std::list<CDateChaiDan*> shapes_;

	std::map<std::string, pConstructor> m_mapCreator;

private:

};

#endif 
